home *** CD-ROM | disk | FTP | other *** search
/ Mission 3 / Mission 3.zip / Mission 3.iso / texte / 7up_pd / format.c < prev    next >
C/C++ Source or Header  |  1998-10-29  |  19KB  |  786 lines

  1. /* Textformatierung */
  2. /*****************************************************************************
  3. *
  4. *                                              7UP
  5. *                                        Modul: FORMAT.C
  6. *                                     (c) by TheoSoft '91
  7. *
  8. *****************************************************************************/
  9. #include <portab.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14. #include <aes.h>
  15. #include <vdi.h>
  16.  
  17. #if GEMDOS
  18. #include <tos.h>
  19. #include <ext.h>
  20. #include "vaproto.h"
  21. #else
  22. #include <alloc.h>
  23. #include <dir.h>
  24. #include <dos.h>
  25. #include <io.h>
  26. #endif
  27.  
  28. #include "alert.h"
  29. #include "windows.h"
  30. #include "forms.h"
  31. #include "7UP.h"
  32. #include "undo.h"
  33.  
  34. extern OBJECT *desktop;
  35. extern char iostring[],*iostr2[];
  36. extern LINESTRUCT *lastwstr;
  37. extern long          lasthfirst,begline, endline;
  38. extern int gl_apid, cut;
  39.  
  40. /* Neuformatieren im RAM. Umkopieren */
  41. static void write_ram(WINDOW *wp, char *buff, long bsize, LINESTRUCT *beg, LINESTRUCT *end)
  42. {
  43.     LINESTRUCT *line;
  44.     char *save,*cp;
  45.  
  46.     graf_mouse(BUSY_BEE,NULL);
  47.     line=beg;
  48.     save=buff;
  49.     while(line!=end->next && ((buff+line->used+1L) < (save+bsize)))
  50.     {
  51.         if(line->used > 0)
  52.         {
  53.             while(line->string[--line->used] == ' ')
  54.                 line->string[line->used] = 0;
  55.             line->used++;
  56.         }
  57.         /* mehrfache Blanks killen */
  58.         while(line->string[0] == ' ')/*MT 24.7.94 führende Blanks raus */
  59.         {
  60.             strcpy(&line->string[0],&line->string[1]);
  61.         }
  62.         cp=strchr(line->string,' ');
  63.         while(cp)
  64.         {
  65.             if(*(cp+1L) == ' ')
  66.                 strcpy(cp,cp+1L);
  67.             cp=strchr((*(cp+1L)==' '?cp:cp+1L),' ');
  68.         }
  69.         strcpy(buff,line->used?line->string:"\r");
  70.         if(line->used && line->next)
  71.         {
  72.             if(!line->next->used)
  73.                 strcat(buff,"\r"); /* Absätze markieren */
  74.             else
  75.                 strcat(buff," ");  /* Blank anhängen */
  76.         }
  77.         buff+=strlen(buff);
  78.         line=line->next;
  79.     }
  80.     strcat(buff,"\r");
  81.     graf_mouse(ARROW,NULL);
  82. }
  83.  
  84. static long mread(char *dst, char *src, size_t count)
  85. {
  86.     register long i;
  87.     
  88.     for(i=0; i<count; i++)
  89.         if(src[i]==' ') /* blank drin? */
  90.         {
  91.             memmove(dst,src,count);
  92.             return(count);
  93.         }
  94.     for(i=count; i ; i++)
  95.         if((src[i]==' ') || (src[i]=='\r'))
  96.         {
  97.             memmove(dst,src,i);
  98.             return(i);
  99.         }
  100. }
  101.  
  102. /* Neuformatieren im RAM. Wiedereinketten */
  103. static int read_ram(WINDOW *wp, char *buff, long bsize, LINESTRUCT **begcut, LINESTRUCT **endcut)
  104. {
  105.     register long k=0, count, count2;
  106.     int blank, enough_ram=TRUE;
  107.     register LINESTRUCT *line, *help1;
  108.     char *cp,*save;
  109.  
  110.     if(wp)
  111.     {
  112.         save=buff;
  113.         graf_mouse(BUSY_BEE,NULL);
  114.         if((line=malloc(sizeof(LINESTRUCT)))!=NULL)
  115.         {
  116.             line->effect=0;
  117.             (*begcut)=line;
  118.             begline=begline=wp->row+wp->hfirst/wp->hscroll;  /* zeilen = 1 */
  119.             line->prev=0L;
  120.             while((enough_ram != -1) && (buff<(save+bsize)))
  121.             {
  122. /* 10.7.94
  123.                 memmove(iostring,buff,wp->umbruch+1);
  124.                 buff+=wp->umbruch+1;
  125.                 iostring[wp->umbruch+1]=0;
  126. */
  127.             /* wenn count2 > wp->umbruch+1 kann der String nicht umbrochen werden */
  128.                 count2=mread(iostring,buff,wp->umbruch+1);
  129.                 buff+=count2;
  130.                 iostring[count2]=0;
  131.  
  132.                 if(iostring[0]==' ')
  133.                     strcpy(iostring,&iostring[1]);
  134.                 if((cp=strchr(iostring,'\r'))!=NULL)
  135.                     *cp=0;
  136.                 count=strlen(iostring);
  137.  
  138.                 if((count2<=wp->umbruch+1) && (count>wp->umbruch))
  139.                 {
  140.                     blank=findlastspace(iostring,wp->umbruch,wp->umbruch+1);
  141.                     if(blank>0)
  142.                     {
  143.                         buff-=(long)(wp->umbruch-blank); /* zurück positionieren */
  144.                         iostring[blank]=0;
  145.                         if(wp->w_state & BLOCKSATZ) /* evtl. Blocksatz formatieren */
  146.                         {
  147.                             blockformat(iostring, wp->umbruch-blank);
  148.                         }
  149.                     }
  150.                 }
  151.                 else
  152.                 {
  153.                     if(count2<=wp->umbruch+1)
  154.                         buff-=(long)(wp->umbruch-count);
  155.                     else
  156.                         buff++; /* Der String kann nicht umbrochen werden. */
  157.                         /* buff steht auf dem Trennblank. Ein Zeichen weiter. */
  158.                 }
  159.                 line->len=strlen(iostring);
  160.                 if((line->string=malloc(line->len + 1)) != NULL)
  161.                 {
  162.                     k++;
  163.                     line->used = line->len;
  164.                     strcpy(line->string,iostring);
  165.                     line->attr=0;     /* zeilenmarkierung */
  166.                     help1=line;
  167.                     if((line->next=malloc(sizeof(LINESTRUCT))) != NULL)
  168.                     {
  169.                         line->effect = 0;
  170.                         line=line->next;
  171.                         line->prev=help1;
  172.                     }
  173.                     else
  174.                     {
  175.                         enough_ram=-1;
  176.                     }
  177.                 }
  178.                 else
  179.                 {
  180.                     enough_ram=-1;
  181.                 }
  182.             }
  183.             if((line->string=malloc(NBLOCKS+1))!=NULL)
  184.             {
  185.                 line->string[0]=0;
  186.                 line->len=NBLOCKS;
  187.                 line->used=0;
  188.                 line->attr=0;
  189.                 line->effect=0;
  190.                 line->next=NULL;
  191.                 k++;
  192.             }
  193.             else
  194.             {
  195.                 line=line->prev;
  196.                 free(line->next);
  197.                 line->next=0L;
  198.             }
  199.             (*endcut)=line;                             /* ende markieren */
  200.             endline=begline + k;
  201.         }
  202.         else
  203.             enough_ram=-1;
  204.         graf_mouse(ARROW,NULL);
  205.         return(enough_ram);
  206.     }
  207.     return(FALSE);
  208. }
  209.  
  210. /* Neuformatieren auf Disk. Umkopieren */
  211. static int _write_disk(WINDOW *wp, char *filename, LINESTRUCT *beg, LINESTRUCT *end)
  212. {
  213.     FILE *fp;
  214.     register LINESTRUCT *line;
  215.     int error;
  216.     register char *cp;
  217.  
  218.     if((fp=fopen(filename,"w"))!=NULL)
  219.     {
  220.         graf_mouse(BUSY_BEE,0L);
  221.         line=beg;
  222.         do
  223.         {
  224.             if(line->used > 0)
  225.             {
  226.                 while(line->string[--line->used] == ' ')
  227.                     line->string[line->used] = 0;
  228.                 line->used++;
  229.             }
  230.             /* mehrfache Blanks killen */
  231.             while(line->string[0] == ' ')/*MT 24.7.94 führende Blanks raus */
  232.             {
  233.                 strcpy(&line->string[0],&line->string[1]);
  234.             }
  235.             cp=strchr(line->string,' ');
  236.             while(cp)
  237.             {
  238.                 if(*(cp+1L) == ' ')
  239.                     strcpy(cp,cp+1L);
  240.                 cp=strchr((*(cp+1L)==' '?cp:cp+1L),' ');
  241.             }
  242.             if(fputs(line->string,fp)==EOF)
  243.             {
  244.                 form_alert(1,Aformat[0]);
  245.                 goto WEITER;
  246.             }
  247.             if(fputs(" ",fp)==EOF)
  248.             {
  249.                 form_alert(1,Aformat[0]);
  250.                 goto WEITER;
  251.             }
  252.             line=line->next;
  253.         }
  254.         while(line != end->next);
  255. WEITER:
  256.         error=ferror(fp);
  257.         fclose(fp);
  258.         if(error)
  259.             unlink(filename);
  260.         graf_mouse(ARROW,0L);
  261.         return(TRUE);
  262.     }
  263.     return(FALSE);
  264. }
  265.  
  266. static int write_disk(WINDOW *wp, LINESTRUCT *begcut, LINESTRUCT *endcut)
  267. {
  268.     char filename[PATH_MAX];
  269.     static int first=TRUE;
  270.  
  271.     if(wp && begcut && endcut)
  272.     {
  273.         scrp_read(filename);
  274.         if(!*filename)
  275.         {
  276. #if GEMDOS
  277.             if(create_clip())
  278.                 scrp_read(filename);
  279.             else
  280.             {
  281.                 form_alert(1,Aformat[1]);
  282.                 return(FALSE);
  283.             }
  284. #endif
  285.         }
  286.         else
  287.         {
  288.             if(first) /* beim erstenmal Clipbrd löschen */
  289.             {
  290.                 scrp_clear();
  291.                 first=FALSE;
  292.             }
  293.         }
  294.         complete_path(filename);
  295. /*
  296.         if(filename[strlen(filename)-1]!='\\')
  297.             strcat(filename,"\\");
  298. */
  299.         strcat(filename,"SCRAP.TXT");
  300.  
  301.         if(!_write_disk(wp, filename, begcut, endcut))
  302.         {
  303.             form_alert(1,Aformat[2]);
  304.             return(FALSE);
  305.         }
  306.         inst_clipboard_icon(desktop,DESKICNB,DESKICNC,FALSE);
  307.         return(TRUE);
  308.     }
  309.     return(FALSE);
  310. }
  311.  
  312. /* Neuformatieren auf Disk. Wiedereinketten */
  313. static int _read_disk(WINDOW *wp, char *filename, LINESTRUCT **begcut, LINESTRUCT **endcut)
  314. {
  315.     FILE *fp;
  316.     register long k=0,filesize;
  317.     int count, blank, enough_ram=TRUE;
  318.     register LINESTRUCT *line, *help1;
  319.  
  320.     if((fp=fopen(filename,"r")) != NULL)
  321.     {
  322.         graf_mouse(BUSY_BEE,0L);
  323.         filesize=filelength(fileno(fp));
  324.         if(filesize==0)
  325.         {
  326.             graf_mouse(M_OFF,0L);
  327.             Wcursor(wp);
  328.             ins_line(wp);
  329.             Wcursor(wp);
  330.             graf_mouse(M_ON,0L);
  331.         }
  332.         else
  333.         {
  334.             if((line=malloc(sizeof(LINESTRUCT)))!=NULL)
  335.             {
  336.                 line->effect=0;
  337.                 (*begcut)=line;
  338.                 begline=begline=wp->row+wp->hfirst/wp->hscroll;  /* zeilen = 1 */
  339.                 line->prev=0L;
  340.                 while((enough_ram != -1) && !feof(fp))
  341.                 {
  342.                     memset(iostring,0,wp->umbruch);
  343.                     count=fread(iostring,wp->umbruch+1,1,fp);
  344.                     if(iostring[0]==' ')
  345.                         strcpy(iostring,&iostring[1]);
  346.                     if(count>0)
  347.                     {
  348.                         blank=findlastspace(iostring,wp->umbruch,wp->umbruch+1);
  349.                         if(blank>0)
  350.                         {
  351.                             fseek(fp,-(long)(wp->umbruch-blank),SEEK_CUR); /* zurück positionieren */
  352.                             iostring[blank]=0;
  353.                             if(wp->w_state & BLOCKSATZ) /* evtl. Blocksatz formatieren */
  354.                             {
  355.                                 blockformat(iostring, wp->umbruch-blank);
  356.                             }
  357.                         }
  358.                     }
  359.                     line->len=strlen(iostring);
  360.                     if((line->string=malloc(line->len + 1)) != NULL)
  361.                     {
  362.                         k++;
  363.                         line->used = line->len;
  364.                         strcpy(line->string,iostring);
  365.                         line->attr=0;     /* zeilenmarkierung */
  366.                         help1=line;
  367.                         if((line->next=malloc(sizeof(LINESTRUCT))) != NULL)
  368.                         {
  369.                             line->effect=0;
  370.                             line=line->next;
  371.                             line->prev=help1;
  372.                         }
  373.                         else
  374.                         {
  375.                             enough_ram=-1;
  376.                         }
  377.                     }
  378.                     else
  379.                     {
  380.                         enough_ram=-1;
  381.                     }
  382.                 }
  383.                 if((line->string=malloc(NBLOCKS+1))!=NULL)
  384.                 {
  385.                     line->string[0]=0;
  386.                     line->len=NBLOCKS;
  387.                     line->used=0;
  388.                     line->attr=0;
  389.                     line->effect=0;
  390.                     line->next=NULL;
  391.                     k++;
  392.                 }
  393.                 else
  394.                 {
  395.                     line=line->prev;
  396.                     free(line->next);
  397.                     line->next=0L;
  398.                 }
  399.                 (*endcut)=line;                             /* ende markieren */
  400.                 endline=begline + k;
  401.             }
  402.             else
  403.                 enough_ram=-1;
  404.         }
  405.         fclose(fp);
  406.         graf_mouse(ARROW,0L);
  407.         return(enough_ram);
  408.     }
  409.     return(FALSE);
  410. }
  411.  
  412. static void read_disk(WINDOW *wp, LINESTRUCT **begcut, LINESTRUCT **endcut)
  413. {
  414.     char filename[PATH_MAX];
  415.  
  416.     if(wp)
  417.     {
  418.         scrp_read(filename);
  419.         complete_path(filename);
  420. /*
  421.         if(filename[strlen(filename)-1] != '\\')
  422.             strcat(filename,"\\");
  423. */
  424.         strcat(filename,"SCRAP.TXT");
  425.  
  426.         switch(_read_disk(wp,filename,begcut,endcut))
  427.         {
  428.             case -1:
  429.                 form_alert(1,Aformat[3]);
  430.             case TRUE:
  431.                 wp->w_state|=CHANGED;
  432.                 break;
  433.             case FALSE:
  434.                 form_alert(1,Aformat[4]);
  435.                 break;
  436.         }
  437.         unlink(filename);
  438.         inst_clipboard_icon(desktop,DESKICNB,DESKICNC,FALSE);
  439.     }
  440. }
  441.  
  442. static int badblock(WINDOW *wp, LINESTRUCT *begcut, LINESTRUCT *endcut)
  443. {                     /* wenn eine Leerzeile enthalten ist, warnen */
  444.     LINESTRUCT *line;
  445.     if(wp && begcut && endcut)
  446.     {
  447.         for(line=begcut; line && line!=endcut->next; line=line->next)
  448.             if(line->used==0)
  449.                 return(TRUE);
  450.     }
  451.     return(FALSE);
  452. }
  453.  
  454. void textformat(WINDOW *wp, LINESTRUCT **begcut, LINESTRUCT **endcut, int abcursor)
  455. {
  456.     long lines,chars;
  457.     char *formbuff;
  458.     LINESTRUCT *help;
  459.     int ret,key_state,lastline=FALSE;
  460.  
  461.     if(wp && !cut && !*begcut && !*endcut)
  462.     {
  463.         if(wp->cstr->used)
  464.         {
  465.             if(!abcursor) /* 30.9.94 letzte Leerzeile vor dem Cursor suchen */
  466.             {
  467.                 for(help=wp->cstr; help->prev; help=help->prev)
  468.                     if(!help->prev->used)
  469.                         break;
  470.             }
  471.             else /* bei Shift ab Cursor */
  472.                 help=wp->cstr;
  473.  
  474.             *begcut=help;
  475.             for(help=wp->cstr; help->next; help=help->next)
  476.                 if(!help->next->used)
  477.                     break;
  478.             *endcut=help;
  479.             for(help=*begcut; help && help!=(*endcut)->next; help=help->next)
  480.             {
  481.                 help->begcol=0;
  482.                 help->endcol=STRING_LENGTH;
  483.                 help->attr|=SELECTED;
  484.             }
  485.             mark_blk(wp,begcut,endcut);
  486.             hndl_blkfind(wp,*begcut,*endcut,SEARBEG);
  487.             lastwstr=wp->wstr;
  488.             lasthfirst=wp->hfirst;
  489.             begline=endline=wp->row+wp->hfirst/wp->hscroll;
  490.             for(help=*begcut; help && help!=(*endcut)->next; help=help->next, endline++)
  491.                 ;
  492.             evnt_timer(25,0);
  493.         }
  494.     }
  495.     if(wp && !cut && *begcut && *endcut)
  496.     {
  497.         if(((*begcut)==wp->fstr && (*endcut)->next==NULL) || badblock(wp,*begcut,*endcut))
  498.             if(form_alert(2,Aformat[5])==1)
  499.                 return;
  500.  
  501.         graf_mouse(M_OFF,0L);
  502.         Wcursor(wp);
  503.  
  504.         if(!(*endcut)->next)
  505.             lastline=TRUE;
  506.  
  507.       free_undoblk(wp, undo.blkbeg);
  508.         cut=cut_blk(wp,*begcut,*endcut);
  509.       undo.flag=copy_blk(wp,*begcut,*endcut,&undo.blkbeg,&undo.blkend);
  510.  
  511.         if(lastline)
  512.         {
  513.             wp->cspos=wp->col=wp->cstr->used-wp->wfirst/wp->wscroll;
  514.             ins_line(wp);
  515.         }
  516.  
  517.         Wcuron(wp);
  518.         Wcursor(wp);
  519.         graf_mouse(M_ON,0L);
  520.  
  521.         (*begcut)->begcol=0;
  522.         (*endcut)->endcol=STRING_LENGTH;
  523.         Wblksize(wp,*begcut,*endcut,&lines,&chars);
  524.         wp->umbruch--;/* Korrektur, arbeitet anders als beim Tippen */
  525.         undo.item=FALSE;
  526. #if GEMDOS
  527.         if((formbuff=malloc(chars+lines+2))!=NULL)/* evtl. zusätzliches Blank */
  528. #else
  529.         if((formbuff=farmalloc(chars+lines+2))!=NULL)/* evtl. zusätzliches Blank */
  530. #endif
  531.         {
  532.             *formbuff=0;
  533.             write_ram(wp,formbuff,chars+lines+2,*begcut,*endcut);
  534.             free_blk(wp,*begcut);
  535.             if(read_ram(wp,formbuff,strlen(formbuff),begcut,endcut)<TRUE)
  536.                 form_alert(1,Aformat[6]);
  537.          store_undo(wp, &undo, *begcut, *endcut, WINEDIT, CUTPAST);
  538.             graf_mouse(M_OFF,0L);
  539.             Wcursor(wp);
  540.             paste_blk(wp,*begcut,*endcut);
  541.             Wcursor(wp);
  542.             graf_mouse(M_ON,0L);
  543. #if GEMDOS
  544.             free(formbuff);
  545. #else
  546.             farfree(formbuff);
  547. #endif
  548.         }
  549.         else
  550.         {
  551.             if(write_disk(wp,*begcut,*endcut))
  552.             {
  553.                 free_blk(wp,*begcut);
  554.                 read_disk(wp,begcut,endcut);
  555.             store_undo(wp, &undo, *begcut, *endcut, WINEDIT, CUTPAST);
  556.                 graf_mouse(M_OFF,0L);
  557.                 Wcursor(wp);
  558.                 paste_blk(wp,*begcut,*endcut);
  559.                 Wcursor(wp);
  560.                 graf_mouse(M_ON,0L);
  561.             }
  562.             else
  563.                 return;
  564.         }
  565.         wp->umbruch++;
  566.         (*endcut)->endcol=0;
  567.         hndl_blkfind(wp,*begcut,*endcut,SEAREND);
  568.         (*endcut)->endcol=STRING_LENGTH;
  569.         *begcut=*endcut=NULL;
  570.         begline=endline=0;
  571.         cut=FALSE;
  572.     }
  573. }
  574.  
  575. /* Textformatierung                                */
  576. /*                          ^F9  = zentriert        */
  577. /*                          ^F10 = rechtsbündig    */
  578. void textformat2(WINDOW *wp, LINESTRUCT **begcut, LINESTRUCT **endcut, int key, int abcursor)
  579. {
  580.     LINESTRUCT *line;
  581.     LINESTRUCT *help;
  582.     char *temp, *cp;
  583.     long i,y;
  584.     int maxlen;
  585.     static int gewarnt=FALSE;
  586.     
  587.     if(wp && !cut && !*begcut && !*endcut)
  588.     {
  589.         if(wp->cstr->used)
  590.         {
  591.             if(!abcursor) /* 30.9.94 letzte Leerzeile vor dem Cursor suchen */
  592.             {
  593.                 for(help=wp->cstr; help->prev; help=help->prev)
  594.                     if(!help->prev->used)
  595.                         break;
  596.             }
  597.             else /* bei Shift ab Cursor */
  598.                 help=wp->cstr;
  599.  
  600.             *begcut=help;
  601.             for(help=wp->cstr; help->next; help=help->next)
  602.                 if(!help->next->used)
  603.                     break;
  604.             *endcut=help;
  605.             for(help=*begcut; help && help!=(*endcut)->next; help=help->next)
  606.             {
  607.                 help->begcol=0;
  608.                 help->endcol=STRING_LENGTH;
  609.                 help->attr|=SELECTED;
  610.             }
  611.             mark_blk(wp,begcut,endcut);
  612.             hndl_blkfind(wp,*begcut,*endcut,SEARBEG);
  613.             lastwstr=wp->wstr;
  614.             lasthfirst=wp->hfirst;
  615.             begline=endline=wp->row+wp->hfirst/wp->hscroll;
  616.             for(help=*begcut; help && help!=(*endcut)->next; help=help->next, endline++)
  617.                 ;
  618.             evnt_timer(25,0);
  619.         }
  620.     }
  621.     if(wp && !cut && *begcut && *endcut)
  622.    {
  623.         maxlen=0;
  624.         for(line=(*begcut); line!=(*endcut)->next; line=line->next)
  625.             maxlen=max(line->used,maxlen);
  626.         if(maxlen >= wp->umbruch)
  627.         {
  628.             form_alert(1,Aformat[9]);
  629.             return;
  630.         }
  631.         if((wp->umbruch > 90) && !gewarnt)/* das dürfte wohl reichen (?) */
  632.         {
  633.             if(form_alert(1,Aformat[7])==1)
  634.                 return;
  635.             gewarnt=TRUE;
  636.         }
  637.         if(TRUE)
  638.         {
  639.             for(line=(*begcut); line!=(*endcut)->next; line=line->next)
  640.             {
  641.                 temp=line->string;
  642.                 line->string=realloc(line->string, wp->umbruch+1);
  643.                 if(!line->string)
  644.                 {
  645.                     line->string=temp;
  646.                     form_alert(1,Aformat[6]);
  647.                     return;
  648.                 }
  649.                 graf_mouse(BUSY_BEE,NULL);
  650.                 line->len=wp->umbruch;
  651.                 /* mehrfache Blanks killen */
  652.                 while(line->string[0] == ' ')/* führende Blanks raus */
  653.                 {
  654.                     strcpy(&line->string[0],&line->string[1]);
  655.                 }
  656.                 cp=strchr(line->string,' ');
  657.                 while(cp)
  658.                 {
  659.                     if(*(cp+1L) == ' ')
  660.                         strcpy(cp,cp+1L);
  661.                     cp=strchr((*(cp+1L)==' '?cp:cp+1L),' ');
  662.                 }
  663.                 line->used=strlen(line->string);
  664.             
  665.                 switch(key)
  666.                 {
  667.                     case FORMLEFT:
  668.                         break;
  669.                     case FORMCENTER:
  670.                         memmove(&line->string[(wp->umbruch-line->used)/2],
  671.                                     line->string,
  672.                                     line->used+1);
  673.                         memset(line->string,' ',(wp->umbruch-line->used)/2);
  674.                         break;
  675.                     case FORMRIGHT:
  676.                         memmove(&line->string[wp->umbruch-line->used],
  677.                                     line->string,
  678.                                     line->used+1);
  679.                         memset(line->string,' ',wp->umbruch-line->used);
  680.                         break;
  681.                 }
  682.                 line->used=strlen(line->string);
  683.                 
  684.             }
  685.             graf_mouse(M_OFF,NULL);
  686.             for(i=0,line=wp->wstr,y=wp->ywork; line!=(*endcut)->next && y < (wp->ywork+wp->hwork); i++, line=line->next, y+=wp->hscroll)
  687.                 if(line->attr & SELECTED)
  688.                 {
  689.                     refresh(wp,line,0,i);
  690.                 }
  691.             wp->w_state |= CHANGED;
  692.             graf_mouse(ARROW,NULL);
  693.         }
  694.     }
  695. }
  696.  
  697. void hndl_textformat(WINDOW *wp, OBJECT *tree, LINESTRUCT **begcut, LINESTRUCT **endcut)
  698. {
  699.     int exit_obj;
  700.     unsigned int hilf;
  701.     extern char alertstr[];
  702.     
  703.     if(wp)
  704.     {
  705.         if(*begcut && *endcut)
  706.         {
  707.             tree[FORMCURSOR].ob_state &= ~SELECTED;
  708.             tree[FORMPARA  ].ob_state &= ~SELECTED;
  709.             tree[FORMMARK  ].ob_state |=  SELECTED; /* gleich Block markieren */
  710.         }
  711.         else
  712.         {
  713.             if(tree[FORMMARK  ].ob_state &  SELECTED) /* ohne Block geht das nicht */
  714.             {
  715.                 tree[FORMCURSOR].ob_state |=  SELECTED;
  716.                 tree[FORMPARA  ].ob_state &= ~SELECTED;
  717.                 tree[FORMMARK  ].ob_state &= ~SELECTED;
  718.             }
  719.         }
  720.         
  721.         sprintf(tree[FORMLENGHT].ob_spec.tedinfo->te_ptext,"%d",wp->umbruch-1);
  722.  
  723.         if(tree[FORMBLOCK ].ob_state & SELECTED)
  724.             tree[FORMLENGHT].ob_flags |= EDITABLE;
  725.         else
  726.             tree[FORMLENGHT].ob_flags &= ~EDITABLE;
  727.         
  728.         
  729.         form_exopen(tree,FALSE);
  730.         do
  731.         {
  732.             exit_obj=form_exdo(tree,0);
  733.             switch(exit_obj)
  734.             {
  735.                 case FORMLEFT:
  736.                 case FORMCENTER:
  737.                 case FORMRIGHT:
  738.                     tree[FORMLENGHT].ob_flags &= ~EDITABLE;
  739.                     objc_update(tree,FORMLENGHT,0);
  740.                     break;
  741.  
  742.                 case FORMBLOCK:
  743.                     tree[FORMLENGHT].ob_flags |= EDITABLE;
  744.                     objc_update(tree,FORMLENGHT,0);
  745.                     break;
  746.                 
  747.                 case FORMHELP:
  748.                     form_alert(1,Aformat[8]);
  749.                     objc_change(tree,exit_obj,0,
  750.                         tree->ob_x,tree->ob_y,
  751.                         tree->ob_width,tree->ob_height,
  752.                         tree[exit_obj].ob_state&~SELECTED,TRUE);
  753.                     break;
  754.             }
  755.         }
  756.         while(exit_obj!=FORMOK && exit_obj!=FORMABBR);
  757.         form_exclose(tree,exit_obj,FALSE);
  758.     
  759.         wp->umbruch=atoi(form_read(tree,FORMLENGHT,alertstr))+1;
  760.         if(wp->umbruch<2)
  761.             wp->umbruch=2;
  762.         if(wp->umbruch>STRING_LENGTH)
  763.             wp->umbruch=STRING_LENGTH;
  764.     
  765.         if(exit_obj == FORMOK)
  766.         {
  767.             if(tree[FORMLEFT  ].ob_state & SELECTED)
  768.                textformat2(wp,begcut,endcut, FORMLEFT, tree[FORMCURSOR ].ob_state & SELECTED);
  769.  
  770.             /*dies ist die alte Methode*/
  771.             if(tree[FORMBLOCK ].ob_state & SELECTED)
  772.             {
  773.                 hilf = wp->w_state;
  774.                 wp->w_state |= BLOCKSATZ;
  775.                 textformat (wp, begcut, endcut, tree[FORMCURSOR ].ob_state & SELECTED);
  776.                 wp->w_state = hilf;
  777.             }
  778.  
  779.             if(tree[FORMCENTER].ob_state & SELECTED)
  780.                 textformat2(wp, begcut, endcut, FORMCENTER, tree[FORMCURSOR ].ob_state & SELECTED);
  781.             if(tree[FORMRIGHT ].ob_state & SELECTED)
  782.                 textformat2(wp, begcut, endcut, FORMRIGHT, tree[FORMCURSOR ].ob_state & SELECTED);
  783.        }
  784.    }
  785. }
  786.